{layout name="layout/header" /}
<link href="root/css/plugins/footable/footable.core.css" rel="stylesheet">

<link href="root/css/plugins/switchery/switchery.css" rel="stylesheet">
<script src="root/js/plugins/switchery/switchery.js"></script>
<!--<link href="root/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">-->

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>管理员列表</h5>
                </div>
                <div class="ibox-content">
                    <p>
                        <a href="{:url('add')}" class="btn btn-success btn-outline refresh">新增</a>
                        <button type="button" class="btn btn-primary btn-outline refresh">刷新</button>
                    </p>
                </div>
                <div class="ibox-content table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>用户名</th>
                                <th>用户组</th>
                                <th>行政单位</th>
                                <th>状态</th>
                                <th>备注</th>
                                <th>最后登录时间</th>
                                <th>最后登录IP</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        {volist name="data" id="vo"}
                            <tr pid="{$vo.id}">
                                <td>{$vo.username}</td>
                                <td>{$vo.role_name}</td>
                                <td>{$vo.name1}{$vo.name2}{$vo.name3}{$vo.name4}{$vo.name5}</td>
                                <td>
                                    <input type="checkbox" class="js-switch update_checkbox" data-field="status" {eq name="$vo.status" value="1"}checked{/eq} />
                                </td>
                                <td><input type="text" class="form-control update_text" data-field="remark" value="{$vo.remark}"></td>
                                <td>{notempty name="$vo.log_time"}
                                    {$vo.log_time|date="Y-m-d H:i",###}
                                    {/notempty}
                                </td>
                                <td>{$vo.log_ip}</td>
                                <td>
                                    <a class="btn btn-success btn-sm" href="{:url('admin/update',['id'=>$vo['id']])}">编辑</a>
                                    {neq name="$vo.is_super" value="1"}
                                    <button class="btn btn-danger btn-sm del" pid="{$vo['id']}">删除</button>
                                    {/neq}
                                </td>
                            </tr>
                        {/volist}
                        </tbody>
                        <tfoot>
                        <tr>
                            <td colspan="5">
                                {$page}
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!--layer-->
<script src="root/js/plugins/layer/layer.min.js"></script>

<script>
    $(document).ready(function() {
        var elem = document.querySelectorAll('.js-switch');
        elem.forEach(function(i,index){
            var a= "a" +index;
            a = new Switchery(i, {
            color: '#1AB394'
            });
        });

        //列表页修改
        $(".update_checkbox").change(function () {
            var field = $(this).attr('data-field');
            var value = $(this).is(':checked')?1:0;
            var id = $(this).parent().parent().attr('pid');
            update(id,field,value);
        });
        //列表页修改
        $(".update_text").blur(function () {
            var field = $(this).attr('data-field');
            var id = $(this).parent().parent().attr('pid');
            var value = $(this).val().trim();
            update(id,field,value);
        });
        function update(id,field,value) {
            $.ajax({
                url:"{:url('ajax_update')}",
                type:'post',
                dataType:'json',
                data:{field:field,value:value,id:id},
                success:function (data) {
                    console.log(data.message);
                    if(data.code == 0){
                        layer.msg(data.message);
                    }
                }
            })
        }
        //删除
        $('.del').click(function(){
            var id = $(this).attr('pid');
            var $this = $(this);

            layer.confirm('确定删掉吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    url:"{:url('ajax_del')}",
                    type:'post',
                    data:{id:id},
                    dataType:'json',
                    success:function (data) {
                        layer.msg(data.msg);
                        if(data.code ==1){
                            $this.parent().parent().remove();
                        }
                    }
                })
            }, function(){

            });

        });
    });

</script>
